package parser

import (
	"fmt"
	"learn/crawler/engine"
	"regexp"
)

var cateRe = regexp.MustCompile(`<a href="(/[^/]+/)">([^<]+)</a>`)

func ParseCategory(contents []byte) engine.ParseResult {
	matches := cateRe.FindAllSubmatch(contents, -1)

	result := engine.ParseResult{}
	for _, m := range matches {
		url := fmt.Sprintf("https://www.zhipin.com%s", string(m[1]))
		result.Requests = append(result.Requests,
			engine.Request{
				Url:        url,
				ParserFunc: JobListParse,
			})
	}

	return result
}
